<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="vn.edu.hungvuongaptech.common.Constant" %>
<%@page import="vn.edu.hungvuongaptech.dao.ProjectDAO" %>
<%@page import="vn.edu.hungvuongaptech.dao.ProductDAO" %>
<%@page import="vn.edu.hungvuongaptech.dao.ProcessDAO" %>
<%@page import="vn.edu.hungvuongaptech.dao.WorkDAO" %>
<%@page import="vn.edu.hungvuongaptech.dao.TimeSheetDAO" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/general.css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/aqua.css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/General.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/zapatec.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/calendar.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/calendar-en.js"></script>
<title>Update TimSheet</title>
<script language="JavaScript" type="text/javascript">
//Javascript validation functions
//http://www.designplace.org/

function isEmpty() {


//change "field1, field2 and field3" to your field names
strfield1 = document.frmUpdateTimeSheet.txtDate.value; 
strfield2 = document.frmUpdateTimeSheet.txtTime.value;
strfield3 = document.frmUpdateTimeSheet.txtDescription.value;

  //Date field
    if (strfield1 == "" || strfield1 == null || strfield1.charAt(0) == ' ')
    {
    alert("\"Date \" is a mandatory field.\nPlease fill and retry.");
    return false;
    }

  //Time field 
    if (strfield2 == "" || strfield2 == null || isNaN(parseFloat(strfield2)) || strfield2.charAt(0) == ' ')
    {
    alert("\"Time\" is a mandatory field.\nPlease fill and retry.");
    return false;
    }

  //Description field 
    if (strfield3 == "" || strfield3 == null || strfield3.charAt(0) == ' ')
    {
    alert("\"Description\" is a mandatory field.\nPlease fill and retry.");
    return false;
    }

    if(!IsNumeric(strfield2))
    return true;

} 
</script>
</head>
<body>
<div id="main-wrap"><!-- S HEAD CONTENT --> <jsp:include
	page="../block/header.jsp" /> <!-- E HEAD CONTENT -->

<div class="space"></div>

<!-- S BODY CONTENT -->
<div id="body">
<div id="center-column">
<form name="frmUpdateTimeSheet" action="UpdateTimeSheetController" method="post"
	onsubmit="return isEmpty()">
	<c:choose>
	 <c:when test='${ not empty param.id and param.id ne "" and param.status ne "Approved"}'>
	 <c:set var="itemTS" value='<%= TimeSheetDAO.getTimeSheetById(Long.valueOf(request.getParameter("id"))) %>' />
	  <table cellpadding="4" align="center">
		<tr>
			<td colspan="2">
			<h3 align="center">Update Record</h3>
			</td>
		</tr>
		<tr>
			<td style="width: 30%"><input type="hidden" name="txtTimeSheetId" id="txtTimeSheetId" value="${ itemTS.timeSheetId }"/>
			</td>
			<td>
			<p class="error_msg"><c:if test='${not empty param.msg}'>
							   ${param.msg}
						   </c:if></p>
			</td>

		</tr>
		<tr>
			<td style="width: 30%">Project Name:</td>
			<td><select id="cboProject" name="cboProject">
				<c:set var="projectList" value="<%= ProjectDAO.getAllProject() %>" />
				<c:forEach items="${projectList}" var="item">
				  <c:choose>
				  <c:when test="${item.projectName eq itemTS.project.projectName }">
				     <option value="${ item.projectId }" selected>${ item.projectName}</option>
				  </c:when> 
				  <c:otherwise>
				    <option value="${ item.projectId }">${ item.projectName}</option>
				  </c:otherwise>
				  </c:choose>
				</c:forEach>
			</select></td>
		</tr>
		<tr>
			<td style="width: 30%">Product Name:</td>
			<td><select id="cboProduct" name="cboProduct">
				<c:set var="productList" value="<%= ProductDAO.getAllProducts() %>" />
				<c:forEach items="${productList}" var="item">
			     <c:choose>
				  <c:when test="${item.productName eq itemTS.product.productName }">
				     <option value="${ item.productId }" selected>${ item.productName}</option>
				  </c:when> 
				  <c:otherwise>
				    <option value="${ item.productId }">${ item.productName}</option>
				  </c:otherwise>
				 </c:choose>
				</c:forEach>
			</select></td>
		</tr>
		<tr>
			<td style="width: 30%">Work:</td>
			<td><select id="cboWork" name="cboWork">
				<c:set var="workList" value="<%= WorkDAO.getAllWorks() %>" />
				<c:forEach items="${workList}" var="item">
				 <c:choose>
				  <c:when test="${item.workName eq itemTS.work.workName }">
				     <option value="${ item.workId }" selected>${ item.workName}</option>
				  </c:when> 
				  <c:otherwise>
				    <option value="${ item.workId }">${ item.workName}</option>
				  </c:otherwise>
				 </c:choose>
				</c:forEach>
			</select></td>
		</tr>
		<tr>
			<td style="width: 30%">Process:</td>
			<td><select id="cboProcess" name="cboProcess">
				<c:set var="processList" value="<%= ProcessDAO.getAllProcess() %>" />
				<c:forEach items="${processList}" var="item">
				 <c:choose>
				  <c:when test="${item.processName eq itemTS.process.processName }">
				     <option value="${ item.processId }" selected>${ item.processName}</option>
				  </c:when> 
				  <c:otherwise>
				    <option value="${ item.processId }">${ item.processName}</option>
				  </c:otherwise>
				 </c:choose>
				</c:forEach>
			</select></td>
		</tr>
		<tr>
			<td style="width: 30%">Date:</td>
			<td><input type="text" name="txtDate" id="txtDate" size="6" value="${itemTS.date}" readonly="readonly"/>
			<img id="imgDate" src="../images/view_calendar_day.png"
				alt="Calendar" height="20px" style="margin-bottom: -5px;" /></td>
		</tr>
		<tr>
			<td style="width: 30%">Time:</td>
			<td><input name="txtTime" id="txtTime" type="text" value="${itemTS.time }"/></td>
		</tr>
		<tr>
			<td style="width: 30%">Description:</td>
			<td style="width: 100px; height: 100px"><textarea
				id="txtDescription" name="txtDescription" cols="40" rows="10">${itemTS.description }</textarea></td>
		</tr>
		<tr>
			<td style="width: 30%">&nbsp;</td>
			<td><input name="btnUpdate" id="btnUpdate" type="submit"
				value="Update" /></input>&nbsp;&nbsp; 
				<input name="btnNo" id="btnNo"
				type="button" value="No" onclick="document.location.href='TimeSheet.jsp'"/></td>
		</tr>
	  </table>
	  <script type="text/javascript">
	  //<![CDATA[
    Zapatec.Calendar.setup({
	firstDay          : 1,
	weekNumbers       : false,
	range             : [2010.01, 2020.12],
	electric          : false,
	inputField        : "txtDate",
	button            : "imgDate",
	ifFormat          : "%m-%d-%Y"
});
//]]>
</script>
	  </c:when>
	  <c:otherwise>
		<p align='center' class='error_msg'><b>This record has been approved by Administrator, you can't change it!!!</b></p>
	  </c:otherwise>
    </c:choose>
</form>
</div>
</div>
<!-- E BODY CONTENT -->

<div class="space"></div>

<!-- S FOOT CONTENT --> <jsp:include page="../block/footer.jsp" /> <!-- E FOOT CONTENT -->
</div>
</body>
</html>